public class HashBucket2<k,v> {
    public class Node<k,v>{
        public k key;
        public v val;
        public Node<k,v> next;

        public Node(k key, v val) {
            this.key = key;
            this.val = val;
        }
    }
    public int usedSize;
    public Node<k,v>[] elem = (Node<k, v>[]) new Node[10];
    //新增元素
    public void put(k key,v val){
        //1.取key的hashcode,再取余得到index
        int hashcode = key.hashCode();
        int index = hashcode % elem.length;
        Node<k,v> cur = elem[index];
        while(cur != null){
            //2.需要使用自定义类内置的equals
            if(cur.key.equals(key)){
                cur.val = val;
                return;
            }
            cur = cur.next;
        }
    }
    //获取元素
    public v get(k key){
        int hashcode = key.hashCode();
        int index = hashcode % elem.length;
        Node<k,v> cur = elem[index];
        while(cur != null){
            if(cur.key.equals(key)){
                return cur.val;
            }
            cur = cur.next;
        }
        return null;
    }
}
